/*
 * FavorableView.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;

/** 单个优惠活动的View */
public class FavorableView extends LinearLayout {

    /** 优惠活动 */
    public static final int STYLE_ACTIVE = 0;

    /** 红包 */
    public static final int STYLE_RED_PAPER = 1;

    /** 限时购 */
    public static final int STYLE_LIMIT_BUY = 2;
    /** 免费赠 */
    public static final int STYLE_FREE = 3;
    /** 秒杀 */
    public static final int STYLE_SECOND_KILL = 4;

    private TextView mTvTitle;

    private TextView mTvContent;

    public FavorableView(Context context) {
        this(context, null);
    }

    public FavorableView(Context context, AttributeSet attrs) {
        super(context, attrs);

        View root =
                LayoutInflater.from(context).inflate(R.layout.item_single_favorable, this, true);

        mTvTitle = (TextView) root.findViewById(R.id.tv_title);
        mTvContent = (TextView) root.findViewById(R.id.tv_content);

        setStyle(STYLE_ACTIVE);
    }

    public void setStyle(int style) {
        switch (style) {
            case STYLE_ACTIVE:
                mTvTitle.setBackgroundResource(R.drawable.bg_red_rect);
                break;
            case STYLE_RED_PAPER:
                mTvTitle.setBackgroundResource(R.drawable.bg_pink_rect);
                break;
            case STYLE_LIMIT_BUY:
                mTvTitle.setBackgroundResource(R.drawable.bg_yellow_rect);
                break;
            case STYLE_FREE:
                mTvTitle.setBackgroundResource(R.drawable.bg_red_rect);
                break;
            case STYLE_SECOND_KILL:
                mTvTitle.setBackgroundResource(R.drawable.bg_red_rect);
                break;
        }
    }

    /**
     * 设置优惠详情
     *
     * @param title 标题
     * @param content 内容
     */
    public void setDetail(String title, String content) {
        mTvTitle.setText(title);
        mTvContent.setText(content);
    }
}
